Skip to content

xls: use the format string of a Format record with any id - #804

Open
hsdfat wants to merge 1 commit into
tafia:masterfrom
hsdfat:xls-format-id-override
Open

hsdfat wants to merge 1 commit into
tafia:masterfrom
hsdfat:xls-format-id-override

Conversation

@hsdfat

@hsdfat hsdfat commented Nov 15, 2026

Copy link
Copy Markdown

Summary

Fixed issue where a numeric cell in an xls file was read as a date when its number format was stored in a Format record with an id from 50 to 58.

parse_format() only accepted the ifmt ranges listed in MS-XLS and dropped the record for any other id. The cell then fell back to the built-in format with that id, and 50 to 58 are the East Asian date formats. The format string of a Format record is now used for any id, so it takes precedence over the built-in format, the same way an explicit numFmt already does for xlsx.

XlsError::InvalidFormat is no longer returned. I left the variant in place because removing it would change the public API.

Related issue

Fixes #798

Testing

Added tests/format_id_overrides_builtin.xls and test_xls_format_id_overrides_builtin. The file is the fix50.xls attached to the issue, unchanged. The issue describes how it was made: an xlsx written with openpyxl, converted to xls with LibreOffice, then the Format and XF records patched so the two custom formats use ids 50 (0.000) and 51 (0.0).

Without the change the test fails with DateTime(3.505) instead of Float(3.505).

Checklist

  • cargo test --all-features passes.
  • cargo fmt -- --check passes.
  • cargo clippy --all-targets --all-features -- -Dwarnings passes.
  • New or changed behavior is covered by a test.
  • Code and tests follow CONTRIBUTING.md.

Other information

I also ran cargo +1.89 check --all-features. I did not run the wasm check or typos locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XLS: FORMAT records with IDs 50-58 are silently rejected -> numeric cells misdetected as dates via builtin East Asian date formats

1 participant